import { Router } from "express";
import { deserializeUser, requireLogin, validate } from "../middlewares";
import { boardSchema, updateBoardSchema } from "../schemas";
import { BoardController } from "../controllers";

const router = Router();

router.post(
  "/",
  validate(boardSchema),
  deserializeUser,
  requireLogin,
  BoardController.create,
);
router.get("/", BoardController.findMany);
router.get("/:id", BoardController.findOne);
router.patch(
  "/:id",
  validate(updateBoardSchema),
  deserializeUser,
  requireLogin,
  BoardController.update,
);
router.delete("/:id", deserializeUser, requireLogin, BoardController.remove);
router.get("/:id/posts", BoardController.findPosts);

export { router as boardRouter };
